#! /usr/bin/python

import math

def isPrime(n):
    if n==2 or n==3 or n==5 or n==7: return True 
    if n==1 or n%2 == 0 or n%3 == 0: return False
    i = 5
    while(i <= math.sqrt(n)):
	if n%i == 0 or n%(i+2) == 0: return False
        i += 6
    return True

primes = [2]

MAX = 10000
for i in range(1, MAX, 2):
    if isPrime(i): primes.append(i)

sums = set()

UPPER = 50000000
#UPPER = 50
for p1 in primes:
    for p2 in primes:
	for p3 in primes:
	    s = p1**2 + p2**3 + p3**4
	    if s > UPPER: break
	    sums.add(s)

print len(sums)
